package com.jy.adscm.wechat.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.wechat.bean.QueryShMachine;
import com.jy.adscm.wechat.bean.ShCustomerInfo;
import com.jy.adscm.wechat.bean.ShMachine;
import com.jy.adscm.wechat.service.ShMachineService;
import com.jy.adscm.wechat.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-09-24
 */
@RestController
@RequestMapping("/adscm/wechat/shMachine")
public class ShMachineController {
    @Autowired
    private RedisOperator redis;
    @Autowired
    ShMachineService shMachineService;
    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryShMachine queryShMachine, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        Page<ShMachine> page=new Page<>(queryShMachine.getCurrentPage(),queryShMachine.getPageSize());
        queryShMachine.setOpenid(openid);
        page =  shMachineService.selectMachines(page,queryShMachine);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("selectLists")
    public SimpleCoreResponse selectLists(HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        List<ShMachine>  shMachines=  shMachineService.selectMachineLists(openid);
        return  new SimpleCoreResponse("200","查询成功",shMachines);
    }
    @RequestMapping("selectByMacCode")
    public SimpleCoreResponse selectByMacCode( String macCode, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        if (!AdscmBaseUtils.getInstance().isNotEmpty(macCode,null)){
            throw new AdscmSystemException("机器码为空");
        }
          ShMachine shMachine=  shMachineService.selectByMacCode(macCode);
        return  new SimpleCoreResponse("200","查询成功",shMachine);
    }
}

